<link rel="stylesheet" href="css/aliceui.min.css"/>
<link rel="stylesheet" href="css/resetui.css"/>
<link rel="stylesheet" href="css/reg.css"/>
<link rel="stylesheet" href="css/distributor.css"/>
<style type="text/css">
#create_new_lnk{display: none;}
.message{border: 1px solid #0088cc;}
	#create_new_lnk{display: none;}
.message{border: 1px solid #0088cc;}
.mctit_nbg{background-image:none;}
.tab_wrap{display:none;}
.tab_show{display:block;}
#create_new_lnk{display: none;}
.message{border: 1px solid #0088cc;}#t {
	width: 324px;
	margin: 5px auto;
	padding:0px;
	border-top: #ccc 1px solid;
	border-left: #ccc 1px solid;
	display:table;
}
#t li {float: left;width: 80px;height: 50px;list-style-type: none;border-right:#ccc 1px solid;
	border-bottom: #ccc 1px solid;text-align: center;line-height: 50px;
}
fieldset{width:807px;height:760px; border: 1px solid #E1E1E1;}
legend{margin-left:15px;font-weight:bold; font-size:14px;color:#121212;}
a { text-decoration:none; color:#000;}
li { list-style:none;}
.center { margin:0 auto; width:800px;}
.title { width:780px; height:30px;  margin-top:-25px; line-height:30px; text-align:right; padding-right:15px;}
.nav { width:800px;  margin-top:15px; overflow:hidden;}
.nav ul li { width:800px; float:left; height:350px;}
.nav ul li ul li{ width:153px; float:left; height:100px; border:1px solid #E1E1E1; margin-left:5px;margin:6px 0 0 6px;}
.nav ul li ul li.first { margin-left:0;}
.red{color:red;}
.wodeziti{margin-left: 13px;
font-weight: bold;
font-size: 12px;
color: ##990F62;}
td {text-align: center; padding: 5px 0;} 
p.error.err_text {width: 110px;}
.mt120{margin-top: -185px;}
.nav #list #l1 img{padding: 9px; border: 1px solid #C9C9C9; -moz-border-radius: 5px; border-radius: 5px;}
/*width="130" height="68" align="left" valign="middle"*/
</style>
<script type="text/javascript">document.title="添加分销商 - <?=$data['web_title']?>";</script>
<!--主体-->
<div class="r_content" id="register">
    <h3 class="mc_title">
        <span class="mctit_1"><span class="mctit_2 aa">添加分销商</span></span>
    </h3>
    <div class="ui-tiptext-container ui-tiptext-container-question mt10">
        <p class="ui-tiptext ui-tiptext-warning">
            <span class="ui-form-required">+</span>直接输入分销商名称（仅限中文）,若列表中存在请直接点“添加”；若不存在，请点“创建新分销商”。<br/>
            <span class="ui-form-required">+</span>添加成功后请点击“价格配置”为分销商配置结算价。<br/>
			<span class="ui-form-required">+</span>同时可显示10条分销商信息。
        </p>
    </div>
    <form id="reg_form" class="reg_form" style="margin:0;">
        <?=$data['csrf_token'];?>
        <input type="hidden" name="action" value="RelationshipCreate"/>
        <input type="hidden" name="actionType" value="CreateDistor"/>
        <input type="hidden" name="dtype" value="1"/>
        <table class="add_table">
            <tbody>
            <tr>
				<td class="tab1" id="alliance_tab2"><span class="ui-form-required">*</span>分销商名称/手机号</td>
                <td class="tab2">
                    <input type="text" id="dname_e" class="ui_inout_allance_add ui_all_w400 required" name="s_val" placeholder="分销商名称/手机号" />
                    <a href="javascript:void(0);" id="create_new_lnk">创建新分销商</a>
                </td>
                <td class="tab3">
                    <p class="normal">分销商名称以中文开头</p>
                    <p class="error err_text"></p>
                    <p class="ok">&nbsp;</p>
                </td>
            </tr>
            </tbody>
        </table>

        <table class="add_table" id="create_new_one" style="display:none;margin-top:10px;">
		<tbody>
		<tr>
			<td class="tab1" id="alliance_tab2"><span class="ui-form-required">*</span>分销商姓名</td>
			<td>
				<input type="text" id="dname_e" class="ui_inout_allance_add ui_all_w400 required" name="company" autocomplete="off">
			</td>
			<td class="tab3">
				<p class="normal">请输入联系人姓名，仅限中文</p>
				<p class="error"></p>
				<p class="ok">&nbsp;</p>
			</td>
		</tr>
		<tr>
			<td class="tab1" id="alliance_tab2"><span class="ui-form-required">*</span>姓名</td>
			<td>
				<input type="text" id="dname_c" data-msg="请输入分销商真实姓名" class="ui_inout_allance_add ui_all_w400 required" name="username" autocomplete="off" />
			</td>
			<td class="tab3">
				<p class="normal">请输入联系人姓名，仅限中文</p>
				<p class="error"></p>
				<p class="ok">&nbsp;</p>
			</td>
		</tr>
		<tr>
			<td class="tab1" id="alliance_tab2"><span class="ui-form-required">*</span>密码</td>
			<td class="tab2">
				<input type="password" data-msg="密码不能为空" class="ui_inout_allance_add ui_all_w400 required" name="password" />
			</td>
			<td class="tab3 tab5">
                <p class="normal">6-16个字符,请使用字母加数字或符号的组合</p>
                <p class="error"></p>
                <p class="ok">&nbsp;</p> 
            </td>
		</tr>
	
		<tr>
			<td class="tab1" id="alliance_tab2"><span class="ui-form-required">*</span>确认密码</td>
			<td class="tab2">
				<input type="password" class="ui_inout_allance_add ui_all_w400 required" name="confirmPwd" />
			</td>
			<td class="tab3">
				<p class="normal">请再次输入密码</p>
				<p class="error"></p>
				<p class="ok">&nbsp;</p>
			</td>
		</tr>
		<tr>
			<td class="tab1" id="alliance_tab2"> 手机号</td>
			<td class="tab2">
				<input type="text" class="ui_inout_allance_add ui_all_w400 " name="mobile" autocomplete="off"/>
			</td>
			<td class="tab3">
				<p class="normal">请输入分销商手机号，必须唯一</p>
				<p class="error"></p>
				<p class="ok">&nbsp;</p>
			</td>
		</tr> 
		<tr>
			<td class="tab1" id="alliance_tab2"> 固定电话</td>
			<td class="tab2"><input type="text" data-msg="请填写公司固定电话" class="ui_inout_allance_add ui_all_w400" autocomplete="off" name="g_tel" /></td>
			<td class="tab3">
				<p class="normal">请填写公司固定电话</p>
				<p class="error"></p>
				<p class="ok">&nbsp;</p>
			</td>
		</tr>
		<tr>
			<td class="tab1" id="alliance_tab1">企业类型</td>
            <td class="tab2" id="distributor_sel">
				<select name="com_type" class="dtlist">
				<option value="加盟门店">加盟门店</option>
				<option value="电商/团购网">电商/团购网</option>
				<option value="旅行社">旅行社</option>
				<option value="淘宝/天猫">淘宝/天猫</option>
				<option value="其他">其他</option>
				</select>
			</td>
        </tr>
		<tr>
			<td>&nbsp;</td>
			<td colspan="2">
				<input type="button" id="distor_btn_c" value="提交" class="submit_btn_d"/>
			</td>
		</tr>
		</tbody>
        </table>
    </form>
	<table id="selected_distor">
    <thead>
    <tr>
        <th class="first">分销商名称</th>
        <th>公司类型</th>
        <th>联系人</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="selected_distor_list" class="hide">
	<tr id="dist_{$id}">
	<td class="first" style="text-align:left">[{$account}]{$dname}</td>
	<td style="text-align:left">{$com_type}</td>
	<td style="text-align:left">{$cname}[{$mobile}]</td>
	<td style="text-align:left">{$btn}</td>
	</tr>
	</tbody>
    <tbody id="selected_show_list">
    <?if(isset($data['admin'])):?>
    <tr id="dist_<?=$data['admin']['id']?>">
        <td class="first">[<?=$data['admin']['account']?>]先行网</td>
        <td>电商</td>
        <td><?=$data['admin']['cname']?>[<?=$data['admin']['mobile']?>]</td>
        <td><a href="javascript:" class="selected_distor_add" data-id="<?=$data['admin']['id']?>">添加</a></td>
    </tr>
    <?endif;?>
    </tbody>
</table>
</div>
<!--快速查找分销商-->
<div class="huanyihuan">
<fieldset>

<legend>快速添加分销商</legend>
<p class="wodeziti">分销平台</p>
<div class="center">
<div class="nav">
    <ul id="list">
    <li id="l1" class="setHeight">
	<?if($_SESSION['dtype']==0):?>
       
		<input type="hidden"  data="0">
		<table width="798" height="119" align="center" id="alliance">
			<a onclick="window.location.href='alliance_join.html?id=4'" style="cursor:pointer;" class="famous" data="先行供销联盟"><img src="images/allall.png"></a>
		</table>
       
	<?else:?>
		<table width="798" height="119" align="center">   
		<tbody>
		<tr>
		<td><img src="../images/fenxiaoshang/xianxing.png"></td>
		<td width="5">&nbsp;</td>
		<td><img src="../images/fenxiaoshang/baise.jpg"></td>
		<td width="5">&nbsp;</td>
		<td><img src="../images/fenxiaoshang/baise.jpg"></td>
		
		</tr>
		<tr>
		<td><a href="javascript:void(0);" class="famous" data="先行供销联盟">旅游同业分销平台</a></td>
		<td>&nbsp;</td>
		<td><a href="javascript:void(0);" class="famous" data="酷秀旅游"></a></td>
		<td>&nbsp;</td>
		<td><a href="javascript:void(0);" class="famous" data="杭州贝竹电子商务有限公司"></a></td>
		</tr>
		</tbody>
		</table>
	<?endif;?> 
	
		
    </li>
	</ul>
</div>
</div>

<p class="wodeziti">OTA电商</p>
<div class="center">
<div class="nav">
    <ul id="list">
    <li id="l1">
		<table width="798" height="230" align="center">
		<tbody>
		<tr>
		<td><img src="images/fenxiaoshang/xiecheng.png"></td>
		<td width="5">&nbsp;</td>
		<td><img src="images/fenxiaoshang/qunaer.png"></td>
		<td width="5">&nbsp;</td>
		<td><img src="images/fenxiaoshang/lvmama.png"></td>
		<td width="5">&nbsp;</td>
		<td><img src="images/fenxiaoshang/tongcheng.png"></td> 
        <td width="5">&nbsp;</td>
       
		
		</tr>
        
		<tr>
		<td><a href="javascript:void(0);" class="famous" data="携程网">携程网</a></td>
		<td>&nbsp;</td>
		<td><a href="javascript:void(0);" class="famous" data="去哪儿">去哪儿</a></td>
		<td>&nbsp;</td>
		<td><a href="javascript:void(0);" class="famous" data="驴妈妈">驴妈妈</a></td>
		<td>&nbsp;</td>
		<td><a href="javascript:void(0);" class="famous" data="同程网">同程网</a></td>
		<td>&nbsp;</td>
		</tr>
        
        
        <tr>        
            <td><img src="images/fenxiaoshang/tuniu.png"></td>
            <td width="5">&nbsp;</td>
            <td><img src="images/fenxiaoshang/weixun.png"></td>
            <td width="5">&nbsp;</td>
            <td><img style="width: auto; height: 50px;" src="images/fenxiaoshang/yaochufa.png"></td>
            <td width="5">&nbsp;</td>
            <td><img style="width: auto; height: 55px;" src="images/fenxiaoshang/kuxiulvyou.png"></td>
            <td width="5">&nbsp;</td>
        </tr>
        
        <tr>        
            <td><a href="javascript:void(0);" class="famous" data="南京途牛旅游网">途牛网</a></td>
            <td>&nbsp;</td>
            <td><a href="javascript:void(0);" class="famous" data="深圳微讯科技信息部">微讯旅游网</a></td>
            <td>&nbsp;</td>
            <td><a href="javascript:void(0);" class="famous" data="广州酷旅旅行社有限公司产品中心">酷旅<span style="padding: 0 2px;">·</span>要出发</a></td>
            <td>&nbsp;</td>  
            <td><a href="javascript:void(0);" class="famous" data="酷秀旅游">酷秀旅游</a></td>
            <td>&nbsp;</td>             
        </tr>
        <tr>        
            <td><img style="width: 130px; height: 55px;" src="images/fenxiaoshang/yikuaiqu.png"></td>
            <td width="5">&nbsp;</td>
           
        </tr>
        <tr>        
            <td><a href="javascript:void(0);" class="famous" data="常州途游网络科技有限公司">一块去</a></td>
            <td>&nbsp;</td>
           
                   
        </tr>
		</tbody>
		</table>
    </li>
	</ul>
</div>
</div>

<p class="wodeziti">团购网</p>
<div class="center">
<div class="nav">
    <ul id="list">
    <li id="l1">
		<table width="798" height="119" align="center">
		<tbody>
		<tr>
		<td><img src="../images/fenxiaoshang/meituan.png"></td>
		<td width="5">&nbsp;</td>
		<td><img src="../images/fenxiaoshang/lashou.png"></td>
		<td width="5">&nbsp;</td>
		<td><img src="../images/fenxiaoshang/nuomi.jpg"></td>
		<td width="5">&nbsp;</td>
		<td><!--<img src="../images/fenxiaoshang/baise.jpg">--><div style="width: 150px;"></div></td>
		</tr>
		<tr>
		<td><a href="javascript:void(0);" class="famous" data="【美团】北京三快在线科技有限公司">美团网</a></td>
		<td>&nbsp;</td>
		<td><a href="javascript:void(0);" class="famous" data="拉手网">拉手网</a></td>
		<td>&nbsp;</td>
		<td><a href="javascript:void(0);" class="famous" data="百度糯米网">百度糯米</a></td>
		<td><a href="javascript:void(0);" class="famous" data=""></a></td>
		</tr>
		</tbody>
		</table>
    </li>
	</ul>
</div>
</div>
</fieldset>
<div class="red">注：添加配置OTA、团购为分销商后，需联系OTA、团购业务上架销售。</div>
</div>
<!-- </div>
</div> -->
<div id="fullbg"></div> 
<div id="dialog"> <p class="close"></p>
	<div class="textarea_ben"></div>
	<div class="sure_btn">
		<input type="button" id="sure" value="同意" class="submit_btn_d"/>
		<a href="#" onclick="closeBg();">不同意</a>
	</div>
</div>
<!--<script type="text/javascript" src="js/jquery.getareas.js"></script>-->
<!--    <script type="text/javascript" src="js/easydialog.min.js"></script>-->
<script type="text/javascript" src="js/fun.inc.js"></script>
<script type="text/javascript" src="js/prod_pub.js"></script>
<script type="text/javascript" src="js/reg_new.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
	$("a#create_new_lnk").on('click', function(){
	if($(this).hasClass('opened')) {
		$("#create_new_one").hide();
		$("table#com_type").show();
		$("#selected_distor").show();
		$(this).removeClass('opened').text('创建新分销商');
	} else {
		$("#create_new_one").show();
		$("table#com_type").hide();
		$("#selected_distor").hide();
		$(this).addClass('opened').text('选择已有分销商');
		if(verify.isTel($("input[name=s_val]").val())){
			$("input[name=company]").val('');
			$("input[name=mobile]").val($("input[name=s_val]").val());
		}else{
			$("input[name=mobile]").val('');
			$("input[name=company]").val($("input[name=s_val]").val());
		}
	}

});
$(document).ready(function(){
	$("#selected_distor").on('click', '.selected_distor_add', function(){
		var did = $(this).attr('data-id');
		var type = $(this).attr('data-type');
		var dname = $(this).attr('data-dname');
		var protocol = $(this).attr('data-protocol');
		var bh = $("body").height(); 
		var a_url = 'call/jh_alliance.php';
		var bw = $("body").width();  
		var param;
		var alliance_p;
		var protocol = protocol;//协议文本
		$("#dialog .textarea_ben").append(protocol);
		$("#dialog .close").html(dname+'为联盟主账号，要给联盟分销产品需加入联盟。');
		param = {
			action: 'AddRelationShip',
			distor: did,
			token : check.getToken()
		},
		alliance_p = {
			action: 'apply',
			aid: type,
			id: did,
			pto: '1',
			us: '1'
		},elem = $(this);
		if(type>0&&type!=''){
			var r=confirm("您欲添加的为先行供销联盟。");
			if (r==true){location.href="alliance_join.html?id=4";}
			else{return false;}
			//}
			//$("#fullbg").css({ height:bh, width:bw, display:"block" });
			//$("#dialog").show(); 
			// $("#dialog").on('click', '#sure', function(){
			// $.post(a_url,alliance_p,function(json_res){
				// if(json_res.status=='success') {
					// elem.parent('td').html('已添加|<a target="_blank" href="priceset.html?did='+did+'">价格配置</a>');
					// alert(json_res.mesg);
					// closeBg();
				// } else {
					// alert(json_res.mesg);
				// }
				// },'json');
				// });
		}
		else{
			 $.post(url,param,function(json_res){
				if(json_res.status=='ok') {
					elem.parent('td').html('已添加|<a target="_blank" href="priceset.html?did='+did+'">价格配置</a>');
				} else {
					alert(json_res.msg);
				}
				},'json');
		}
		});
	});

});
$("input[name=s_val]").on('keyup', function(){
	if(verify.isTel($(this).val())){
        tab3.find(".error").html('请输入电话号码,分销商名称或分销商拼音首字母').hide();
		getMember($(this),true);
		return false;
	}else if(verify.is_chinese($(this).val())){
		tab3.find(".error").html('请输入电话号码,分销商名称或分销商拼音首字母').hide();
		getMember($(this),false);
    }else if(verify.isAlpha($(this).val())){
		tab3.find(".error").html('请输入电话号码,分销商名称或分销商拼音首字母').hide();
		getMember($(this),false);
	}else{
		tab3 = $(this).parents("tr").find('td.tab3');
		tab3.find(".error").html('请输入电话号码,分销商名称或分销商拼音首字母').show();
		tab3.show();
	}
});


$("input[name=s_val]").on('focus', function(){
	if(!verify.is_chinese($(this).val()) && !verify.isTel($(this).val()) && !verify.isAlpha($(this).val())){
		tab3 = $(this).parents("tr").find('td.tab3');
		tab3.find(".error").html('请输入电话号码,分销商名称或分销商拼音首字母').show();
		tab3.show();
	}

	$("#create_new_one").hide();
	$("table#com_type").show();
	$("#selected_distor").show();
	$("a#create_new_lnk").removeClass('opened').text('创建新分销商');
});

	
// 获取搜索分销商列表
function getMember(obj,isTel){
	var val = obj.val(),listTxt = '', bEqual=false;
	if(val=='') return false;
	if(isTel){// 手机号搜索
		$.getJSON('call/jh_mem.php',{action:'mobileSearch',mobile:val})
		.done(function(salers){
			
		   /*if((typeof salers.ajaxMobile!='undefined' && salers.ajaxMobile!=null) || (typeof salers.status!='undefined' && salers.status!=1) ){
				listTxt=getParTpl(salers);
			}else{
				$("#create_new_lnk").show();
			}*/	
            for(var k in salers) {
				if(salers[k].dname==val) bEqual=true;
				listTxt+=getParTpl(salers[k]);
			}
			$("#selected_show_list").html("");
			$("#selected_show_list").append(listTxt);
            if(bEqual==false) $("#create_new_lnk").show();
		});
	}else{ // 分销商名称模糊搜索
		$.getJSON('call/jh_mem.php',{action:'fuzzyGetDname',dname:val})
		.done(function(salers){
			for(var k in salers) {
				if(salers[k].dname==val) bEqual=true;
				listTxt+=getParTpl(salers[k]);
			}
			$("#selected_show_list").html("");
			$("#selected_show_list").append(listTxt);
			if(bEqual==false) $("#create_new_lnk").show();
		});

	}
	
	
};
function closeBg() { 
    $("#fullbg,#dialog").hide(); 
} 
</script>